﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Linq;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Text;
using Maticsoft.Model;
using Maticsoft.BLL;
using FineUI;

namespace EmptyProjectNet20
{
    public partial class login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Session["UserName"] = null;
        }
        protected void btnLogin_Click(object sender, EventArgs e)
        {
            if (RadioButtonListIdentity.SelectedValue == "Student")
            {
                Maticsoft.BLL.Student CurrentStudent = new Maticsoft.BLL.Student();
                if (!CurrentStudent.Exists(tbxUserName.Text))
                {
                    Alert.Show("不存在该用户！请核对用户名", MessageBoxIcon.Error);
                }
                else
                {
                    string CurrentStuName = tbxUserName.Text;
                    Maticsoft.Model.Student CurrentStuInform=CurrentStudent.GetModel(CurrentStuName);
                    //密码匹配 登录成功!
                    if (tbxPassword.Text == CurrentStuInform.S_Password)
                    {
                        Session["UserName"] = CurrentStuInform.S_Id;
                        Response.Redirect("~/console_student.aspx");
                    }
                    else
                    {
                        Alert.Show("密码错误", MessageBoxIcon.Error);
                    }
                }
            }
            if (RadioButtonListIdentity.SelectedValue == "Teacher")
            {
                Maticsoft.BLL.Teacher CurrentTeacher = new Maticsoft.BLL.Teacher();
                if (!CurrentTeacher.Exists(tbxUserName.Text))
                {
                    Alert.Show("不存在该用户！请核对用户名", MessageBoxIcon.Error);
                }
                else
                {
                    string CurrentTeaName = tbxUserName.Text;
                    Maticsoft.Model.Teacher CurrentTeacherInfom = CurrentTeacher.GetModel(CurrentTeaName);
                    if (tbxPassword.Text == CurrentTeacherInfom.T_Password)
                    {
                        Session["UserName"] = CurrentTeacherInfom.T_Id;
                        Response.Redirect("~/console_teacher.aspx");
                    }
                    else
                    {
                        Alert.Show("密码错误", MessageBoxIcon.Error);
                    }
                }
            }
            if (RadioButtonListIdentity.SelectedValue == "Admin")
            {
                Maticsoft.BLL.Admin CurrentAdmin = new Maticsoft.BLL.Admin();
                if (!CurrentAdmin.Exists(tbxUserName.Text))
                {
                    Alert.Show("不存在该用户！请核对用户名", MessageBoxIcon.Error);
                }
                else
                {
                    string CurrentAdminName = tbxUserName.Text;
                    Maticsoft.Model.Admin CurrentAdminInfom = CurrentAdmin.GetModel(CurrentAdminName);
                    if (tbxPassword.Text == CurrentAdminInfom.A_Password)
                    {
                        Session["UserName"] = CurrentAdminName;
                        Response.Redirect("~/console_admin.aspx");
                    }
                    else
                    {
                        Alert.Show("密码错误", MessageBoxIcon.Error);
                    }
                }
            }
        }


        protected void btnRegeistry_Click(object sender, EventArgs e)
        {
            if (RadioButtonListIdentity.SelectedValue == "Student")
            {
                Response.Redirect("~/registry_student.aspx");
            }
            if (RadioButtonListIdentity.SelectedValue == "Teacher" || RadioButtonListIdentity.SelectedValue == "Management")
            {
                Response.Redirect("~/registry_teacher.aspx");
            }

           // Response.Redirect();
        }

        



    }
}
